home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / util / vbbook / vbbook.doc < prev    next >
Text File  |  1991-09-07  |  27KB  |  714 lines

  1. VB BOOK - Utility to print ASCII text files to LaserJet Series II, IIp or III 
  2. in booklet format.
  3.  
  4. Based on the program, PC BOOK, by Jay Munro, Copyright 1990 PC Magazine - 
  5. Ziff Davis - Jay Munro.  Original Copyright still applicable (as far as I'm
  6. concerned).
  7.  
  8. Originally written by Jay Munro and converted to Visual Basic by Dennis Scott 
  9. on 1 September 1991.
  10.  
  11. Documentation adapted from original PCBOOK.DOC file:
  12. ----------------------------------------------------
  13.  
  14. Purpose:  
  15.  
  16. VB BOOK prints README and similar ASCII files in booklet format on an HP 
  17. LaserJet II, IIp, or III printer.  Uses two-sided printing in landscape mode, 
  18. with Line Printer font so that four standard pages of 80 characters per line, 
  19. 66 lines per page are printed on each sheet without formatting changes.
  20.  
  21. Remarks:  
  22.  
  23. The filename can designate any ASCII text file in which each line is 
  24. terminated with a Carriage Return/Line Feed combination.  Page Feed characters 
  25. can be added to force breaks in addition to those implicit in the 60-line 
  26. (68-line if a header is used) page length.
  27.  
  28. The original switches in PC Book have been replaced with Windows Checkboxes.
  29. Any or all of the Checkboxes can be used to create a one-line header that 
  30. prints the filename, page number, and date, on all but blank pages.  The Wrap 
  31. Checkbox causes lines exceeding 80 characters to wrap; by default such lines 
  32. are wrapped.  
  33.  
  34. Output can now be directed to LPT1, LPT2, COM1, COM2, or File.  Noted that
  35. you must set the proper parameters for your port before printing to a COM
  36. port.  If File is selected, you will be prompted to enter an output filename.
  37.  
  38. VB BOOK sequences the page printing so that all side-one pages are printed in 
  39. one pass.  The sheets are then put back in the LaserJet paper tray and all 
  40. side-two pages are printed.  The finished booklet can then be created with a 
  41. single fold.  When using the normal (top) LaserJet output bin the pass-one 
  42. sheets should be reinserted in the paper tray without any relative change
  43. in orientation.  If rear output from the printer is used, the sheets must be
  44. turned over as a group before reinsertion.  
  45.  
  46. Requirements:
  47.  
  48. VB Book requires Windows 3.  The Visual Basic Run Time file, VBRUN100.DLL, 
  49. must be in the path (recommend putting it in your Windows directory).  
  50. Modifications will require Microsoft Visual Basic Version 1.0.  Both the 
  51. executable and the source files for VB Book are provided.
  52.  
  53. Comments to QuickBASIC programmers:
  54.  
  55. The conversion of PC Book from QuickBASIC to Visual Basic (VB) was undertaken 
  56. as an exercise in converting original QuickBASIC (QB) source code into VB code.
  57. It was surprisingly easy!  
  58.  
  59. The hardest part was deciding HOW the screens (forms in VB) should look.  
  60. Actually designing the forms is very easy.  Once the forms were designed, I 
  61. just used "load text" to get the original QB code into the main form.  VB does 
  62. almost everything automatically.  For example, all SUBs are automatically 
  63. created and the old code placed in them.  
  64.  
  65. Some things will need to be changed, of course.  Any input from the user 
  66. (QBs Input, Line Input, and Inkey commands) needs to converted to "InputBox$" 
  67. functions.  Similarly, the "print" statements (with corresponding Locate's) 
  68. were converted to "MsgBox" functions or a form created to place them onto.  
  69. The QB code that performed initialization was placed in the main form's 
  70. Form_Load procedure.  All Declare's were removed.  Most of the above changes
  71. were accomplished by pressing F5 (run) and letting VB tell me what it didn't
  72. like.  I just used the ol' cut & paste to put things in the right place.
  73.  
  74. I then defined what should happen when each of the controls on the forms were 
  75. activated (usually clicked) and wrote the code into those areas.  Putting the 
  76. drive, directory, and file selection boxes on the screen and activating them 
  77. is phenomenally easy!  
  78.  
  79. The overall concepts of VB are a little difficult to comprehend at first but 
  80. then it clicks and it all becomes quite simple.  I would highly recommend that
  81. you take the tutorial before doing anything.  If you don't, you will not 
  82. comprehend what's going on and will probably get disgusted and quit.
  83.  
  84. This conversion took about a day to do because of having to learn VB.  If I 
  85. had to do it again I could probably complete it in an hour or less.  Please
  86. note that the code has not been "cleaned up" - some debugging code may still
  87. be there.
  88.  
  89. Recommended additions:  
  90.  
  91. Want some practice with VB?  Why not add:  A screen preview of output while 
  92. printing (or before printing or instead of printing) and status display of 
  93. percent completed.  
  94.  
  95. If anyone adds this capability or changes the code in some other way, please 
  96. be kind enough to send me a copy.
  97.  
  98. Please send comments or suggestions to:
  99.  
  100.      Dennis Scott
  101.      CompuDirect
  102.      9102 Ocean Gate
  103.      San Antonio, TX 78242
  104.      (512)623-6856
  105.  
  106. Disclaimer:
  107.  
  108. The standard disclaimer applies:  Use this program at you own risk.  Myself, 
  109. and the original Copyright holder, will not be held responsible for anything!
  110.  
  111. The Source Code:
  112. ----------------
  113.  
  114. The following is a complete listing of the VB source code, included here for 
  115. those to see that do not yet own VB.  For those that do own VB, the forms and 
  116. code are also included in the archive.  Just place all files in their own
  117. directory then open the VBBOOK project.  Note that almost all of the following
  118. code was originally PC Book code - very little had to be added for VB.
  119.  
  120. The Global form (VBBOOK.BAS):
  121. -----------------------------
  122. Type Flags                           'Misc flag variables
  123.   CurDate As Integer
  124.   DoHeader As Integer
  125.   FileTitle As Integer
  126.   LineLen As Integer
  127.   LineWrap As Integer
  128.   PgNumber As Integer
  129. End Type
  130.  
  131. 'The VBBOOK.FRM form: (used for the first little box that goes away in 5 sec's.)
  132. '--------------------
  133. '(No code in this form.  Just displays a message for 5 secs)
  134.  
  135. 'The VBBOUT.FRM form:
  136. '--------------------
  137. '(No code in this form.  It's a blank, full-page form used to cover up the
  138. 'desktop.  There should be a better way to do this!)
  139.  
  140. 'The Main module, VBBINP.FRM: (This is where all the selections are done.)
  141. '----------------------------
  142. 'Declarations section:
  143. 'Note that Dim Shared is not really needed but VB done it during the automatic
  144. 'conversion from QuickBasic code so I left it that way.  
  145. Dim Shared ESC$, FF$, LF$, filename$, OUTFILE$, NL$
  146. Dim Shared page%, num$, tune%
  147. Dim Shared PC As Flags
  148. Dim lastchange As Integer
  149.  
  150. Const fileboxclick = 0, dirsboxclick = 1         'Used by file selection routine
  151. Const true = -1, false = 0
  152.  
  153. 'Now the Subs start:
  154. Static Sub BuildArray (ptrarray&(), pgcount%)
  155.    MaxLines% = 66                                'Maximum number of lines
  156.    Offset& = 1                                   'Start of file (seek point)
  157.    Open filename$ For Binary Access Read As #1 Len = 1   'Open file to check
  158.    TotalSize& = LOF(1)                           'Get LEN of file so we don't read too far
  159.    FileLeft& = TotalSize&                        'Setup a counter to show whats left
  160.    'FRE is not supported by VB.  Just set it to 64K
  161.    MemAvail& = 65536                             'FRE(FileName$) - 2048            'Check available string memory
  162.    If MemAvail& < 2048 Then Error 14             'Force out of memory error
  163.    SixteenK% = 16384
  164.  
  165.    If TotalSize& > SixteenK% Then                'Set a buffer size
  166.       If MemAvail& > SixteenK% Then              'If the file is larger than 16K
  167.          BufAvail& = SixteenK%                   'Set it to 16k
  168.       Else
  169.          BufAvail& = MemAvail&
  170.       End If
  171.    Else
  172.       If TotalSize& < MemAvail& Then             'Otherwise set it to file size
  173.          BufAvail& = TotalSize&
  174.       End If
  175.       BuffSize% = BufAvail&
  176.    End If
  177.  
  178.    pgcount% = 1                                  'Initialize page count
  179.    ptrarray&(pgcount%) = 1                       'First pointer is always 1
  180.    LnCount% = 0                                  'Initialize line count
  181.  
  182. GetPage:                                         'Read the file
  183.                                                  
  184.   If FileLeft& < BufAvail& Then                  'Check amount left to read
  185.      Buffer$ = Space$(FileLeft&)                 'If less than our buffer, use lessor
  186.   Else
  187.      Buffer$ = Space$(BufAvail&)                 'Otherwise use full buffer size
  188.   End If
  189.  
  190.   Get #1, Offset&, Buffer$                       'Read in a buffers worth
  191.   stptr% = 1                                     'Pointer into buffer$
  192.   LastLine% = 0                                  'remember last position
  193.  
  194. PageCheck:
  195.   TempLn% = InStr(stptr%, Buffer$, LF$)          'Position of next linefeed
  196.   temppg% = InStr(stptr%, Buffer$, FF$)          'Position of next pagefeeds
  197.  
  198.   If temppg% Then                                'If there was a page feed
  199.      If temppg% < TempLn% Or TempLn% = 0 Then    '  was it before our linefeed?
  200.         pgcount% = pgcount% + 1                  '  yes then bump page count
  201.         ptrarray&(pgcount%) = Offset& + temppg%  '  set next array element
  202.         stptr% = temppg% + 1                     '  set instr pointer
  203.         LnCount% = 0                             '  reset linecount
  204.         If stptr% < Len(Buffer$) Then GoTo PageCheck 'and loop back for more
  205.       End If
  206.   End If
  207.  
  208.   If TempLn% Then                                'Linefeed
  209.     If PC.LineWrap Then                           'If Line Wrap, check length
  210.         If TempLn% - stptr% > PC.LineLen Then     'Greater than 80?
  211.             Do                                   'check for line wrap
  212.                 LnCount% = LnCount% + 1          'increment line
  213.                 If LnCount% = MaxLines% Then
  214.                     GoTo PageBreak               '> 66 lines
  215.                 End If
  216.                 stptr% = stptr% + PC.LineLen
  217.             Loop While TempLn% - stptr% > PC.LineLen
  218.         End If
  219.     End If
  220.     LnCount% = LnCount% + 1                      'Increment page count
  221.  
  222. PageBreak:
  223.      If LnCount% = MaxLines% Then
  224.         pgcount% = pgcount% + 1
  225.             If pgcount% > 512 Then
  226.                msg$ = "Too may pages - printing only 512."
  227.                MsgBox msg$, 0, "Notice"
  228.                GoTo EndBuild
  229.             End If
  230.         ptrarray&(pgcount%) = Offset& + TempLn%  'point to next in point in file
  231.         LnCount% = 0
  232.      End If
  233.      
  234.      stptr% = TempLn% + 1                        'point ahead 1 byte for next scan
  235.      If stptr% <= Len(Buffer$) Then
  236.         GoTo PageCheck                           'keep checking
  237.      End If
  238.   End If
  239.  
  240.   Offset& = Offset& + Len(Buffer$)              'Pointer into file (tally)
  241.   stptr% = 1                                    'Reset Buffer pointer
  242.   FileLeft& = TotalSize& - Offset&              'Calculate how much is left
  243.   If Offset& < TotalSize& Then GoTo GetPage     'If more text in file, keep going
  244.  
  245. EndBuild:
  246.   ptrarray&(pgcount% + 1) = TotalSize&          'Set last pointer to end of file
  247.  
  248. Close #1                                        'Close input file
  249. End Sub                                         'End of BuildArray Sub
  250.  
  251. Sub Label1_load ()
  252.     'This section is not used at this time
  253.     Print String$(80, 61)
  254.     Print "PCBook - PC Magazine Booklet Printing Utility"
  255.     Print "Copyright 1990 PC Magazine  Ziff Davis  Jay Munro"
  256.     Print
  257.     Print "Converted to Visual Basic by Dennis Scott"
  258.     Print String$(80, 61)
  259. End Sub
  260.  
  261. Static Sub DoMacro (num$)
  262.     Print #2, ESC$; "&f"; num$; "y2X";     'execute the macro
  263. End Sub
  264.  
  265. Static Sub EndMacro (num$)
  266.     Print #2, ESC$; "&f"; num$; "y1X";          'Send end of macro command
  267.     Print #2, ESC$; "&f"; num$; "y9X";          'Make it temporary (10 to be permanent)
  268. End Sub
  269.  
  270. Static Sub Header (page%)
  271.     hdr$ = Space$(PC.LineLen)                     'Create a string to print
  272.    
  273.     If PC.FileTitle Then                          'Print the filename
  274.         Mid$(hdr$, 40 - Len(filename$) \ 2) = UCase$(filename$)
  275.     End If
  276.  
  277.     If PC.PgNumber Then                           'Print the current page
  278.         PTemp$ = "Page" + Str$(page%)
  279.         If page% Mod 2 Then
  280.             Mid$(hdr$, PC.LineLen - Len(PTemp$)) = PTemp$ 'odd page, right side
  281.         Else
  282.             Mid$(hdr$, 1) = PTemp$               'even page, left side
  283.         End If
  284.     End If
  285.  
  286.     If PC.CurDate Then                            'Print the current date
  287.         If page% Mod 2 Then
  288.             Mid$(hdr$, 1) = Date$                'even page, left side
  289.         Else
  290.             Mid$(hdr$, PC.LineLen - Len(Date$)) = Date$  'odd page, right side
  291.         End If
  292.     End If
  293.     Print #2, hdr$                               'Print the Header
  294.     Print #2,                                    ' and skip a line for readability
  295.  
  296. End Sub
  297.  
  298. Static Sub LJLocate (X%, Y%)                'Laser Jet cursor locate
  299.     Temp$ = ESC$ + "&a" + LTrim$(Str$(Y%)) + "r" + LTrim$(Str$(X%)) + "C"
  300.     Print #2, Temp$;
  301. End Sub
  302.  
  303. Static Sub printlogo ()                  'Banner logo (About VB Box!)
  304.     msg$ = "                   VB Book" + NL$
  305.     msg$ = msg$ + "     Converted to Visual Basic" + NL$
  306.     msg$ = msg$ + "             by Dennis Scott." + NL$
  307.     msg$ = msg$ + NL$
  308.     msg$ = msg$ + "Send Comments/Suggestions to:" + NL$
  309.     msg$ = msg$ + "               CompuDirect" + NL$
  310.     msg$ = msg$ + "             9102 Ocean Gate" + NL$
  311.     msg$ = msg$ + "              San Antonio, TX" + NL$
  312.     msg$ = msg$ + "               (512)623-6856" + NL$
  313.     MsgBox msg$, 0, "About VB Book"
  314. End Sub
  315.  
  316. Sub PrintSetup ()                               'Send codes to prepare printer
  317.     Print #2, ESC$; "E";                        'Reset laserjet (simple isn't it!)
  318.     Print #2, ESC$; "&l1o5.45C";                'Select lineprinter font"
  319.     Print #2, ESC$; "(s0p16.66H";               '  and pitch
  320.     Print #2, ESC$; "&l0L";                     'Turn off page feed at 66 lines
  321.  
  322.     If PC.LineWrap Then                          'Wrap lines > 80 chars
  323.        Print #2, ESC$; "&s0C";
  324.     End If
  325.  
  326.     Print #2, ESC$; "&l2E";                     'Top margin 2 lines
  327.  
  328.     Call StartMacro("1")                        'Left side macro
  329.          Print #2, ESC$; "9";                   'Reset left - right margins
  330.          Print #2, ESC$; "&a0l80M";             'set left margin 0, right 80
  331.     Call EndMacro("1")
  332.  
  333.     Call StartMacro("2")                        'Right side macro
  334.          Print #2, ESC$; "9";                   'Reset left - right margins
  335.          Print #2, ESC$; "&a95l175M";           'set left margin 95, right 175
  336.     Call EndMacro("2")
  337.  
  338. End Sub
  339.  
  340. Static Sub StartMacro (num$)
  341.     Print #2, ESC$; "&f"; num$; "Y";            'Macro will have an id of Num$
  342.     Print #2, ESC$; "&f0X";                     'Start the macro now
  343. End Sub
  344.  
  345. Sub Form_Click ()
  346.     'If user clicks anywhere on the form, call the about box
  347.     Call printlogo
  348. End Sub
  349.  
  350. 'This is the main code - everything is actually called from here and this
  351. 'is where most of the VB changes are located
  352. Sub go_click ()
  353.  
  354. 'VB Code for Drive, Directory, and File selections
  355. If index >= 3 Then End
  356. If lastchange = dirsboxclick Then
  357.     dir1.path = dir1.list(dir1.listindex)
  358. Else
  359.     If file1.filename <> "" Then
  360.         ChDrive drive1.drive
  361.         ChDir file1.path
  362.         filename$ = file1.filename
  363.     Else
  364.         msg$ = "Sorry!  You must first select a file."
  365.         abort% = MsgBox(msg$, 49, "No application chosen.")
  366.         If abort% = 2 Then                     'cancel button
  367.             End
  368.         End If
  369.     End If
  370. End If
  371. lastchange = fileboxclick
  372.  
  373. ReDim ptrarray&(513)                            'total number of pages (512)
  374. On Error GoTo ErrorDept                         'Error trapping
  375.  
  376. 'Ensure that we have a file name (user may have clicked DoIt without
  377. 'entering a filename)
  378.  
  379. GetName:
  380.     If Len(filename$) = 0 Then
  381.        If tune% Then Beep
  382.         msg$ = "Enter a file name to print: "
  383.         Title$ = "Filename"                             ' Set title.
  384.         Default$ = ""
  385.         NewName$ = InputBox$(msg$, Title$, Default$)    ' Get user input.
  386.         If Len(NewName$) = 0 Then                       ' Check if valid.
  387.             msg$ = "You did not input a valid Filename." + NL$
  388.             msg$ = msg$ + "Click on OK to End Program"
  389.             MsgBox msg$, 0, Title$                      ' Display message.
  390.             GoTo OutHere
  391.         End If
  392.     End If
  393.  
  394. 'Build index array for pages in FileName$
  395.    'Have not converted status display
  396.    'Print
  397.    'Print "Reading file "; filename$
  398.    Call BuildArray(ptrarray&(), page%)          'Built pointer array
  399.  
  400. 'Figure number of pages needed
  401.    If page% Mod 4 Then                          'Even multiples of 4 only
  402.       page% = page% + (4 - page% Mod 4)         '  correct for less
  403.    End If
  404.  
  405.    'Have not converted status display
  406.    'Print
  407.    'Print "You will print "; Page% \ 4; "sheets" 'Report total number of pages
  408.    'Print
  409.  
  410.    'JustCount% is set to false always due to status section not being
  411.    'converted to VB
  412.    If JustCount% Then
  413.       Print "Press any key to continue, or ESC to cancel printing"
  414.       GoSub KeyIn
  415.    End If
  416.  
  417.     Open OUTFILE$ For Output As #2              'Open printer or output file
  418.     Call PrintSetup                             'Set up printer
  419.  
  420. 'Page parsing variables
  421.    LeftSide% = page%
  422.    RightSide% = 1
  423.    FirstPass% = -1
  424.  
  425. Open filename$ For Binary As #1                 'Open the input file
  426.     'Have not converted status display
  427.     'Print "Printing Side 1 to "; outfile$;     'Track what is going on
  428.  
  429. 'Start of print routine
  430.  
  431. DoPass:
  432.    Bookmark% = (page% \ 4)                      'Flag for halfway through
  433.    If Bookmark% = 0 Then Bookmark% = 1          'Force 1 if too small
  434.  
  435. 'Read text and send to printer or file
  436. Do                                              'Print the right side of the page first
  437.     If ptrarray&(RightSide% + 1) = 0 Then       'If blank, then skip it
  438.        GoTo NextPage
  439.     End If
  440.     Call DoMacro("2")                           'Start on right side
  441.     LJLocate 95, 0                              'Home the cursor
  442.  
  443.     If PC.DoHeader Then Call Header(RightSide%) 'Header if needed
  444.     Buffer$ = Space$(ptrarray&(RightSide% + 1) - ptrarray&(RightSide%))
  445.  
  446.     Get #1, ptrarray&(RightSide%), Buffer$      'Read in a page
  447.  
  448.     If InStr(Buffer$, FF$) Then                 'If the last character is a PF
  449.        Print #2, Left$(Buffer$, InStr(Buffer$, FF$) - 1); 'print only text
  450.     Else
  451.        Print #2, Buffer$;                       'Otherwise print full line
  452.     End If
  453.  
  454. NextPage:
  455.     If ptrarray&(LeftSide% + 1) = 0 Then        'Don't print blank pages
  456.        GoTo NextPage1
  457.     End If
  458.     Call DoMacro("1")                           'Reset margins for left side
  459.     LJLocate 0, 0                               'Home the cursor
  460.     If PC.DoHeader Then Call Header(LeftSide%)   'Header if needed
  461.     Buffer$ = Space$(ptrarray&(LeftSide% + 1) - ptrarray&(LeftSide%))                'Setup buffer for input
  462.     If LeftSide% = 0 Then                       'If pointing at blank page, skip
  463.        GoTo NextPage1
  464.     End If
  465.     Get #1, ptrarray&(LeftSide%), Buffer$       'Read in a page
  466.  
  467.     If InStr(Buffer$, FF$) Then                 'if the last character is a PF
  468.        Print #2, Left$(Buffer$, InStr(Buffer$, FF$) - 1); 'print only text
  469.     Else                                        'print only text
  470.        Print #2, Buffer$;                       'otherwise print all
  471.     End If
  472.  
  473. NextPage1:
  474.     Print #2, FF$;                              'Page feed
  475.     LeftSide% = LeftSide% - 2                   'Calculate next page in series
  476.     RightSide% = RightSide% + 2
  477.     Bookmark% = Bookmark% - 1                   'Track our progress
  478.  
  479. Loop Until Bookmark% = 0                        'Print pages until halfway through
  480.  
  481. 'Pause between sides to allow for paper reinsertion
  482.     If FirstPass% Then                          'If side one, prompt and get 2nd side
  483.        msg$ = "First Pass has been Completed." + NL$
  484.        msg$ = msg$ + "Insert paper back in tray and Click OK"
  485.        If tune% Then Beep
  486.  
  487. WaitKey:                                        'Press any key to continue loop
  488.       MsgBox msg$, 0, "Waiting"
  489.       FirstPass% = 0                            'Flag for second pass
  490.       'Have not converted status display
  491.       'msg$ = "Printing Side 2 to " + outfile$
  492.       'Print msg$                                'Report on progress
  493.       GoTo DoPass
  494.     End If                                      'End of first pass
  495.  
  496.     'Printing is done now
  497.     msg$ = "Printing completed."
  498.     If tune% Then Beep
  499.     MsgBox msg$, 64, "Done"
  500.  
  501. PrtReset:
  502.     Print #2, ESC$; "E";                        'Reset laserjet
  503.  
  504. OutHere:
  505.     Close                                       'Close all files
  506.     End                                         'Thats all for now
  507.  
  508. 'Error handler.  Converted to VB errors.
  509. ErrorDept:
  510.     Beep
  511.     msg$ = "*** Error ***" + NL$
  512.     Select Case Err
  513.       Case 482
  514.          msg$ = msg$ + "Printer error."
  515.       Case 68
  516.          msg$ = msg$ + "Device is unavailable."
  517.       Case 71
  518.          msg$ = msg$ + "Insert a disk in the drive and close the door."
  519.       Case 57
  520.          msg$ = msg$ + "Device Input/Output Error (Check Printer!)."
  521.       Case 61
  522.          msg$ = msg$ + "Disk is full."
  523.       Case 64, 52
  524.         msg$ = msg$ + "That filename is illegal."
  525.       Case 76
  526.         msg$ = msg$ + "That path doesn't exist."
  527.       Case 54
  528.         msg$ = msg$ + "Can't open your file for that type of access."
  529.       Case 55
  530.         msg$ = msg$ + "This file is already open."
  531.       Case 62
  532.         msg$ = msg$ + "This file has a nonstandard end-of-file marker" + NL$
  533.         msg$ = msg$ + "or an attempt was made to read beyond the end-" + NL$
  534.         msg$ = msg$ + "of-file marker."
  535.       Case Else
  536.          msg$ = msg$ + "Error number " + Str$(Err)
  537.       End Select
  538.       GoSub AWayOut
  539.       Resume
  540.  
  541. AWayOut:
  542.    abort% = MsgBox(msg$, 17, "ERROR")
  543.  
  544. KeyIn:
  545.       If abort% = 2 Then                     'If user presses Cancel, Exit
  546.          Close
  547.          End
  548.       End If
  549. Return
  550.  
  551. 'End of main module
  552. End Sub
  553.  
  554. Sub Dir1_Change ()
  555.     file1.path = dir1.path
  556.     file1.SetFocus
  557. End Sub
  558.  
  559. Sub Dir1_Click ()
  560.     lastchange = dirsboxclick
  561. End Sub
  562.  
  563. Sub File1_Click ()
  564.     'use the following line to put filename in frame
  565.     'if using a frame:
  566.     'inname.caption = "Load " + file1.filename
  567.     lastchange = fileboxclick
  568. End Sub
  569.  
  570. Sub File1_DblClick ()
  571.     'Allow the user to double-click on an input file and start printing
  572.     Call go_click
  573. End Sub
  574.  
  575. 'CLKx Subs are the Check Boxes for selecting whether to use speaker, etc
  576. Sub clk1_Click ()
  577.       'Toggle on/off
  578.       If PC.FileTitle = 0 Then
  579.         PC.FileTitle = -1
  580.         PC.DoHeader = -1
  581.       Else
  582.         PC.FileTitle = 0
  583.         'Still have to do the Header if clk2 or clk3 buttons are checked
  584.         If (clk2.value = -1) Or (clk3.value = -1) Then
  585.             PC.DoHeader = -1
  586.         Else
  587.             PC.DoHeader = 0
  588.         End If
  589.       End If
  590. End Sub
  591.  
  592. Sub clk2_Click ()
  593.       'Toggle on/off
  594.       If PC.CurDate = 0 Then
  595.         PC.CurDate = -1
  596.         PC.DoHeader = -1
  597.       Else
  598.         PC.CurDate = 0
  599.         'Still have to do the Header if clk1 or clk3 buttons are checked
  600.         If (clk1.value = -1) Or (clk3.value = -1) Then
  601.             PC.DoHeader = -1
  602.         Else
  603.             PC.DoHeader = 0
  604.         End If
  605.       End If
  606. End Sub
  607.  
  608. Sub clk3_Click ()
  609.       'Toggle on/off
  610.       If PC.PgNumber = 0 Then
  611.         PC.PgNumber = -1
  612.         PC.DoHeader = -1
  613.       Else
  614.         PC.PgNumber = 0
  615.         'Still have to do the Header if clk1 or clk2 buttons are checked
  616.         If (clk1.value = -1) Or (clk2.value = -1) Then
  617.             PC.DoHeader = -1
  618.         Else
  619.             PC.DoHeader = 0
  620.         End If
  621.       End If
  622. End Sub
  623.  
  624. Sub clk4_Click ()
  625.     'Toggle on/off
  626.     tune% = Not tune%
  627. End Sub
  628.  
  629. Sub clk5_Click ()
  630.       'Toggle on/off
  631.       PC.LineWrap = Not PC.LineWrap
  632. End Sub
  633.  
  634. Sub Drive1_Change ()
  635.     dir1.path = drive1.drive
  636. End Sub
  637.  
  638. Sub Cancel_Click ()
  639.     'If user clicks on the Cancel button then ...
  640.     Close
  641.     End
  642. End Sub
  643.  
  644. 'This Sub is ran when the VBBINP.FRM is loaded (ie, Showed)
  645. Sub Form_Load ()
  646.     'Put the options in the output port/filename Combobox
  647.     comboutname.AddItem "LPT1"
  648.     comboutname.AddItem "LPT2"
  649.     comboutname.AddItem "COM1"
  650.     comboutname.AddItem "COM2"
  651.     comboutname.AddItem "file"
  652.     comboutname.text = comboutname.list(0)    'default to LPT1
  653.     OUTFILE$ = "LPT1"
  654.     'set default check-box values
  655.     tune% = -1
  656.     PC.FileTitle = -1
  657.     PC.DoHeader = -1
  658.     PC.CurDate = -1
  659.     PC.PgNumber = -1
  660.     PC.LineWrap = -1
  661.     'set some variables
  662.     ESC$ = Chr$(27)                      'Standard ESC code
  663.     FF$ = Chr$(12)                       'Page Feed
  664.     LF$ = Chr$(10)                       'Line Feed
  665.     NL$ = Chr$(13) + Chr$(10)            'CR and LF (New Line)
  666.     JustCount% = 0                       'Not allowing "just counting"
  667.     PC.LineLen = 80                       'Maximum length of line
  668. End Sub
  669.  
  670. 'User clicks on the Combobox
  671. Sub comboutname_Click ()
  672.     'Select where to send the output
  673.     Select Case comboutname.text
  674.     Case "LPT1"
  675.         OUTFILE$ = "LPT1"
  676.     Case "LPT2"
  677.         OUTFILE$ = "LPT2"
  678.     Case "COM1"
  679.         OUTFILE$ = "COM1"
  680.     Case "COM2"
  681.         OUTFILE$ = "COM2"
  682.     Case "file"
  683.         If file1.filename = "" Then           'If no input filename is selected
  684.             comboutname.text = "LPT1"         ' default back to LPT1
  685.             OUTFILE$ = "LPT1"
  686.             msg$ = "You must select an input filename first!"
  687.             MsgBox msg$, 32
  688.             file1.SetFocus                    'set focus to file list box
  689.             Exit Sub
  690.         End If
  691.  
  692.         'Now make up a default output filename with same 
  693.         'name and PRN as the extension
  694.         OUTFILE$ = UCase$(Left$(file1.filename, InStr(file1.filename, ".")) + "PRN")
  695.         
  696.     msg$ = "WAIT" + NL$ + "Enter filename to print to:"
  697.         OUTFILE$ = InputBox$(msg$, "Output File Name", OUTFILE$) 'Get a filename
  698.         If OUTFILE$ <> "" Then
  699.             comboutname.text = UCase$(OUTFILE$)         'put filename in combo box
  700.             go.SetFocus
  701.         Else
  702.             'Insist on a filename
  703.             comboutname.text = "LPT1"
  704.             OUTFILE$ = "LPT1"
  705.             file1.SetFocus                              'set focus to file list box
  706.         End If
  707.     End Select
  708. End Sub
  709.  
  710. Sub Picture1_Click ()
  711.     Call printlogo                          'Show the "about" box
  712. End Sub
  713.  
  714.